<template>
	<view class="content">
		<view class="courseclick">
			<view class="list" v-for="(item,index) in itemList" :key="index" :class="{ select: selectedIdx === index }"
				@click="selectItem(index)">
				<view class="price">
					<view class="pricea">
						{{item.name}}
					</view>
					<view class="plus">
					</view>
				</view>
			</view>
		</view>
		<view class="information" v-if="selectedIdx==0">
			<view class="discountul" v-for="(item,index) in indexlist" :key="index">
				<view class="discountli">
					<view class="left" v-if="item.type ==1">
						<view class="minus">
							<text>￥</text>
							{{item.deduction}}
						</view>
						<view class="full">
							满{{item.useCondition}}可用
						</view>
					</view>
					<view class="left" v-if="item.type ==2">
						<view class="minus">
							{{item.discount}}折
						</view>
						<view class="full">
							满{{item.useCondition}}可用
						</view>
					</view>
					<view class="right">
						<view class="fullname">
							{{item.name}}
						</view>
						<view class="use">
							<view class="date">
								{{item.effectiveDate}}- {{item.deadlineDate}}
							</view>
							<button v-if="item.status == 0" class="send">使用</button>
							<button v-if="item.status == 1" class="send">已用</button>
							<button v-if="item.status == 2" class="send">失效</button>
						</view>
						<view class="describe">
							<view class="instructions" @click="appear(index)">
								使用说明<uni-icons :type="upanddown" size="16" color="#333333"></uni-icons>
							</view>
						</view>
					</view>
				</view>
				<view class="explanationcontent" v-if="introduce == index">
					<view class="" v-if="item.type ==2">
						{{item.discount}}折，满{{item.useCondition}}可用
					</view>
					<view class="" v-if="item.type ==1">
						价值{{item.deduction}}，满{{item.useCondition}}可用
					</view>

				</view>
			</view>
		</view>
		<view class="information" v-if="selectedIdx==1">
			<view class="discountul" v-for="(item,index) in indexlist" :key="index">
				<view class="discountli">
					<view class="left" v-if="item.type ==1">
						<view class="minus">
							<text>￥</text>
							{{item.deduction}}
						</view>
						<view class="full">
							满{{item.useCondition}}可用
						</view>
					</view>
					<view class="left" v-if="item.type ==2">
						<view class="minus">
							{{item.discount}}折
						</view>
						<view class="full">
							满{{item.useCondition}}可用
						</view>
					</view>
					<view class="right">
						<view class="fullname">
							{{item.name}}
						</view>
						<view class="use">
							<view class="date">
								{{item.effectiveDate}}- {{item.deadlineDate}}
							</view>
							<button v-if="item.status == 0" class="send">使用</button>
							<button v-if="item.status == 1" class="send">已用</button>
							<button v-if="item.status == 2" class="send">失效</button>
						</view>
						<view class="describe">
							<view class="instructions" @click="appear(index)">
								使用说明<uni-icons :type="upanddown" size="16" color="#333333"></uni-icons>
							</view>
						</view>
					</view>
				</view>
				<view class="explanationcontent" v-if="introduce == index">
					<view class="" v-if="item.type ==2">
						{{item.discount}}折，满{{item.useCondition}}可用
					</view>
					<view class="" v-if="item.type ==1">
						价值{{item.deduction}}，满{{item.useCondition}}可用
					</view>
				</view>
			</view>
		</view>
		<view class="information" v-if="selectedIdx==2">
			<view class="discountul" v-for="(item,index) in indexlist" :key="index">
				<view class="discountli">
					<view class="left" v-if="item.type ==1">
						<view class="minus">
							<text>￥</text>
							{{item.deduction}}
						</view>
						<view class="full">
							满{{item.useCondition}}可用
						</view>
					</view>
					<view class="left" v-if="item.type ==2">
						<view class="minus">
							{{item.discount}}折
						</view>
						<view class="full">
							满{{item.useCondition}}可用
						</view>
					</view>
					<view class="right">
						<view class="fullname">
							{{item.name}}
						</view>
						<view class="use">
							<view class="date">
								{{item.effectiveDate}}- {{item.deadlineDate}}
							</view>
							<button v-if="item.status == 0" class="send">使用</button>
							<button v-if="item.status == 1" class="send">已用</button>
							<button v-if="item.status == 2" class="senda">失效</button>
						</view>
						<view class="describe">
							<view class="instructions" @click="appear(index)">
								使用说明<uni-icons :type="upanddown" size="16" color="#333333"></uni-icons>
							</view>
						</view>
					</view>
				</view>
				<view class="explanationcontent" v-if="introduce == index">
					<view class="" v-if="item.type ==2">
						{{item.discount}}折，满{{item.useCondition}}可用
					</view>
					<view class="" v-if="item.type ==1">
						价值{{item.deduction}}，满{{item.useCondition}}可用
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		myCoupons, //根据订单金额查询可用的优惠券列表
		getCouponPage //我的优惠券列表
	} from '../../request/api.js'
	export default {
		data() {
			return {
				selectedIdx: 0,
				itemList: [{
						name: '未使用'
					},
					{
						name: '已使用'
					},
					{
						name: '已失效'
					}
				],
				accordionVal: '',
				accordionVala: '',
				upanddown: 'bottom',
				introduce: -1,
				selectedIdxa: 0,
				index: null,
				indexlist: [],
				pageNo: 1,
			};
		},
		onReachBottom() {
			console.log(111);
			if (this.total <= this.indexlist.length) {
				uni.showToast({
					title: '已加载全部数据',
					icon: "none"
				});
			} else {
				this.pageNo++;
				this.getCouponPagea()
			}
		},
		onLoad(options) {

		},
		onShow() {
			this.getCouponPagea('0')
		},
		methods: {
			getCouponPagea(index) {

				uni.showLoading({
					title: '加载中...'
				})
				let that = this
				getCouponPage({
					memberId: uni.getStorageSync('userInfo').id,
					status: index,
					order: 'asc',
					pageNo: this.pageNo
				}).then(res => {
					console.log(res);
					uni.hideLoading()
					that.indexlist = that.indexlist.concat(res.result.records)
					that.total = res.result.total; //数据总条数

				})
			},
			appear(index) {
				if (this.introduce === index) {
					this.introduce = null;
				} else {
					this.introduce = index;
				}
			},
			selectItem(index) {
				this.indexlist = []
				this.selectedIdx = index;
				this.getCouponPagea(index)
			},
		},

	};
</script>

<style scoped lang="less">
	.content {
		width: 100%;
		min-height: 100vh;
		box-sizing: border-box;
		// padding: 16rpx;
		// padding-top: 0rpx;
		background: #f6f6f6;
		// padding-top: 20rpx;
		padding-bottom: 250rpx;
	}

	.courseclick {
		padding: 30rpx 16rpx;
		padding-bottom: 0;
		margin-top: 12rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-bottom: 24rpx;

		.list {
			// margin-bottom: 50rpx;
			border-radius: 20rpx;
			padding-bottom: 26rpx;
			display: flex;
			justify-content: space-between;
			// text-align: center;
			font-size: 36rpx;
			margin-right: 36rpx;
			color: #979797;

			font-size: 28rpx;
			font-weight: 700;

			.name {
				color: #333333;
				font-size: 24rpx;
				font-weight: 500;
				padding: 0 8rpx;
			}

			.price {
				position: relative;

				.pricea {}


			}
		}

		.select {
			margin-right: 36rpx;
			color: #333;
			display: flex;
			font-size: 28rpx;
			font-weight: 700;

			.plus {
				width: 58rpx;
				height: 4rpx;
				border-radius: 160rpx;
				background: #ff9d34;
				position: absolute;
				bottom: -15rpx;
				left: 50%;
				transform: translateX(-50%);
			}
		}
	}

	.information {
		padding-top: 0;
		margin: 32rpx;
	}

	.discountul {
		margin-bottom: 20rpx;
		position: relative;

		.usedalready {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;

			.image {
				width: 686rpx;
				height: 206rpx;
			}
		}

		.discountli {
			border-radius: 20rpx;
			background: #ffffff;
			// padding: 30rpx 20rpx 26rpx 24rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				width: 198rpx;
				height: 206rpx;
				border-radius: 20rpx 0 0 20rpx;
				padding: 30rpx 0rpx 26rpx 24rpx;
				background: rgba(255, 156, 51, 0.2);
				color: #ff9c33;
				text-align: center;
				margin-right: 12rpx;

				.minus {
					color: #ff9c33;
					font-size: 72rpx;
					font-weight: 700;
					margin-top: 30rpx;
					margin-bottom: 15rpx;

					text {
						color: #ff9c33;
						font-size: 36rpx;
						font-weight: 500;
					}
				}

				.full {
					color: #ff9c33;
					font-size: 28rpx;
					font-weight: 700;
				}
			}

			.right {
				// width: 100%;

				// padding: 30rpx 20rpx 26rpx 24rpx;
				padding-right: 20rpx;

				.fullname {
					color: #333333;
					font-size: 36rpx;
					font-weight: 700;
				}

				.use {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 8rpx;
					margin-bottom: 22rpx;

					.date {
						color: #333333;
						font-size: 24rpx;
						font-weight: 400;
						margin-right: 28rpx;

					}

					.send {
						width: 138rpx;
						height: 50rpx;
						border-radius: 258rpx;
						background: #ff9c33;
						color: #ffffff;
						text-align: center;
						line-height: 50rpx;
						font-size: 28rpx;
						font-weight: 500;
					}

					.senda {
						width: 138rpx;
						height: 50rpx;
						border-radius: 258rpx;
						background: #b4b1b0;
						color: #ffffff;
						text-align: center;
						line-height: 50rpx;
						font-size: 28rpx;
						font-weight: 500;
					}
				}

				.describe {
					.instructions {
						color: #333333;
						font-size: 24rpx;
						font-weight: 400;

					}
				}
			}
		}

		.explanationcontent {
			background: #ffffff;
			padding: 30rpx 20rpx 26rpx 224rpx;
			color: #9e9e9e;
			font-size: 24rpx;
			font-weight: 400;
		}
	}
</style>